<template>
  <el-container class="container">
    <el-aside width="200px">
      <div class="logo">
        <img src="../assets/logo.png" alt="" />
        <h4>方舟新闻</h4>
      </div>
      <el-menu
        class="el-menu-vertical-demo"
        background-color="#333333"
        text-color="#fff"
        active-text-color="#ffd04b"
        default-active="1"
      >
        <el-menu-item
          index="1"
          @click="$router.push('/articleList').catch((err) => {})"
        >
          <i class="el-icon-menu"></i>
          <span slot="title">文章列表</span>
        </el-menu-item>
        <el-menu-item
          index="2"
          @click="$router.push('/addArticleList').catch((err) => {})"
        >
          <i class="el-icon-plus"></i>
          <span slot="title">发布文章</span>
        </el-menu-item>
      </el-menu>
    </el-aside>

    <el-container>
      <!-- 头部 -->
      <el-header>
        <div class="user">
          <img
            :src="userObj.head_img | fixImgUrl"
            alt=""
            v-if="userObj.head_img"
          />
          <span class="name">{{ userObj.nickname }}</span>
          <div class="exit" @click="exit">
            <i class="el-icon-switch-button"></i>
          </div>
        </div>
      </el-header>
      <!-- 主体内容 -->
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      userObj: {},
    };
  },
  methods: {
    exit() {
      this.$router.replace("/login");
    },
  },
  created() {
    this.$axios({
      url: "/user/" + localStorage.getItem("userid"),
    }).then((res) => {
      // console.log(res);
      if (res.data.message == "获取成功") {
        this.userObj = res.data.data;
      }
    });
  },
};
</script>

<style lang="less" scoped>
.container {
  height: 100vh;
  .logo {
    margin-top: 10/ 360 * 100vw;
    img {
      width: 30 / 360 * 100vw;
      object-fit: cover;
      border-radius: 50%;
    }
    h4 {
      margin-top: -5/ 360 * 100vw;
    }
  }
}
header {
  display: flex;
  align-items: center;
  .user {
    display: flex;
    align-items: center;
    img {
      width: 10/ 360 * 100vw;
      height: 10/ 360 * 100vw;
      border-radius: 50%;
      object-fit: cover;
    }
    .name {
      margin: 10px;
    }
    .exit {
      color: red;
      margin-left: 10px;
    }
  }
}

.el-menu {
  border-right: none;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
}

.el-aside {
  background-color: #333;
  color: #333;
  color: #fff;
  text-align: center;
  line-height: 200px;
  line-height: 60px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
